Conditions | 3 |
Paths | 4 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* |
||
31 | function payWithStripe(e) { |
||
32 | |||
33 | e.preventDefault(); |
||
34 | function stripeResponseHandler(status, response) { |
||
35 | if (response.error) { |
||
36 | /* Visual feedback */ |
||
37 | submitPaymentButton.html('Try again').prop('disabled', false); |
||
38 | /* Show Stripe errors on the form */ |
||
39 | $form.find('.payment-errors').text(response.error.message); |
||
40 | $form.find('.payment-errors').closest('.row').show(); |
||
41 | } else { |
||
42 | /* Visual feedback */ |
||
43 | submitPaymentButton.html('Processing <i class="fa fa-spinner fa-pulse"></i>'); |
||
44 | /* Hide Stripe errors on the form */ |
||
45 | $form.find('.payment-errors').closest('.row').hide(); |
||
46 | $form.find('.payment-errors').text(""); |
||
47 | // response contains id and card, which contains additional card details |
||
48 | |||
49 | var token = response.id; |
||
50 | stripeTokenElement.val(token); |
||
51 | delegateForm.submit(); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | if (stripeTokenElement.val() != '') { |
||
56 | delegateForm.submit(); |
||
57 | } |
||
58 | |||
59 | /* Abort if invalid form data */ |
||
60 | if (!validator.form()) { |
||
|
|||
61 | return; |
||
62 | } |
||
63 | |||
64 | /* Visual feedback */ |
||
65 | $('#submit-payment').html('Validating <i class="fa fa-spinner fa-pulse"></i>').prop('disabled', true).removeClass('btn-success'); |
||
66 | |||
67 | /* Create token */ |
||
68 | var expiry = $form.find('[name=cardExpiry]').payment('cardExpiryVal'); |
||
69 | var ccData = { |
||
70 | number: $form.find('[name=cardNumber]').val().replace(/\s/g,''), |
||
71 | cvc: $form.find('[name=cardCVC]').val(), |
||
72 | exp_month: expiry.month, |
||
73 | exp_year: expiry.year, |
||
74 | name: $form.find('[name=cardName]').val(), |
||
75 | address_line1: $form.find('[name=cardLine1]').val(), |
||
76 | address_line2: $form.find('[name=cardLine2]').val(), |
||
77 | address_city: $form.find('[name=cardCity]').val(), |
||
78 | address_state: $form.find('[name=cardState]').val(), |
||
79 | address_zip: $form.find('[name=cardZip]').val(), |
||
80 | address_country: $form.find('[name=cardCountry]').val() |
||
81 | }; |
||
82 | |||
83 | Stripe.card.createToken(ccData, stripeResponseHandler); |
||
84 | } |
||
85 | /* Fancy restrictive input formatting via jQuery.payment library*/ |
||
143 | }, 250); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.